<?php
	session_start();

	include_once("functions_db.php");
	include 'headermenu.php';	
	
	ini_set("SMTP","93.115.117.60");
?>

<html>
<head>
</head>
<body>
	<?php   
		 //modificare: prin if-ul de mai jos se verifica daca s-a realizat logarea; deasemenea acesta trebuie sa apara in fiecare pagina
		if(ISSET($_SESSION["userId"]) == FALSE)
		{
			 echo "<script type =\"text/javascript\">window.location.href=\"methodology.php\";</script>";
			 
			 exit();
		}  
	?>


				<div id="doc" class="yui-t7">
				<div id="bd" role="main">
				<div class="yui-gc">
				<link rel="stylesheet" href="yui.css" type="text/css">
	<?php
	
		dbConn();		

		$mail = "";
		$account = "";
		$message = "";
		$mailmessage = "";
		$accountmessage = "";
		$prioritymessage = "";
		$url	= "";
		
		if(ISSET($_POST["submitButton"]))
		{
			if($_POST["mail"] != null && $_POST["priority"] != null)
			{
				$result = mysql_query("INSERT INTO users(mail,account,priority) VALUES('".$_POST['mail']."','".$_SESSION["account"]."','".$_POST['priority']."');")or die(mysql_error());
			
				$url = "<a href=\"http://localhost/mp/methodology/RegistrationUser.php?mail=".$_POST['mail']."&account=".$_SESSION["account"]."\">Click the invitation link</a>";
				echo $url;
				/*$result = mail($_POST["mail"], "Subject: Invitation", $url, "From: office@enterprise-concept.com \r\n");
				
				if($result == TRUE)
				{
					echo "<p>Mail sent</p>";
				}
				else
				{
					echo "<p>Mail not sent</p>";
				} */
			}
			else
				{
					
					//$temp = 1;
	
					if(empty($_POST["mail"]))
						{
							$mailmessage = "Mail is required!";
						}
		
					if(empty($_POST["account"]))
						{
							$accountmessage = "Account is required!";			
						}
					if(empty($_POST["priority"]))
						{
							$prioritymessage = "Priority is required!";			
						}
					
				}
		}
	?>
			<form name="invitatie" method="POST" action="invitation.php">				
				<p>
					Mail <font color="#ff0000">*</font><br />
					<input name="mail" id="mail" type="text" value="">&nbsp;<?php echo $mailmessage ?>
				</p>
				
				<p>
					Priority <font color="#ff0000">*</font><br />
					<select name="priority" id="priority">
					<option value="1">to view</option>
					<option value="2">to view and edit a document</option>
					<option value="3">to view, edit and accept a document </option>
				</p>
				<br/>
				
				<input type="submit" name="submitButton" id="submitButton" value="Submit" />			
			</form>
	</div>
	</div>
	</div>
</body>
</html>